<table class="bid-agency-list" data-page="${page}" data-page-size="${pageSize}" data-count="${count}">
	<tr class="title-row">
		<th class="text-center">机构名称</th>
		<th class="text-center">地址</th>
		<th class="text-center">邮编</th>
		<th class="text-center">网址</th>
		<th class="text-center">配置单位</th>
	</tr>
	<#if data??> <#list data as d>
	<tr data-id="${d[0].id}" style="cursor: pointer;">
		<td class="">${(d[0].company)!'-'}</td>
		<td class="text-center">${(d[0].addr)!'-'}</td>
		<td class="text-center">${(d[0].zip)!'-'}</td>
		<td class="text-center">${(d[0].url)!'-'}</td>
		<td class="text-center">${(d[1].name)!'-'}</td>
	</tr>
	</#list> </#if>
</table>

<script src="${request.contextPath}/core/js/jquery.form.js"></script>
<script src="${request.contextPath}/js/suredy-list.js"></script>
<script src="${request.contextPath}/app/js/form-checker.js"></script>
<script type="text/javascript">
	$(function() {
		var showWin = function(id) {
			var title = '新建招投标机构';
			
			if (id) {
				title = '修改招投标机构';
			}

			id = id || '';
			
			$.suredy.showModal({
				icon : 'icon-plus',
				title : title,
				uri : '${request.contextPath}/config/bid-agency/create?admin=true&id=' + id,
				okClick : function() {
					var form = $('form.form-add-bid-agency');

					// 校验表单
					if (!$.suredy.formChecker(form)) {
						return false;
					}

					form.ajaxSubmit({
						success : function(data, textStatus, jqXHR) {
							if (!data) {
								alert('操作失败！');
								return false;
							}

							$.suredy.loadContent('${request.contextPath}/config/bid-agency/list');
							$.suredy.closeModal();
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert('操作失败！\n' + errorThrown);
							return false;
						}
					});
				}
			});
		};
	
		// edit
		$('.bid-agency-list tr[data-id]').on('click', function() {
			var $this = $(this);
			var id = $this.data('id');
			
			showWin(id);
		});

		$('.bid-agency-list').list({
			search : false,
			checkbox : true,
			paginate : function(page, pageSize, key) {
				$.suredy.loadContent('${request.contextPath}/config/bid-agency/list?page=' + page + '&pageSize=' + pageSize);
			},
			btns : [ {
				text : '新建',
				icon : 'icon-edit',
				style : 'btn-primary btn-sm',
				click : function(page, pageSize, key) {
					showWin();
				}
			}, {
				text : '删除',
				icon : 'icon-edit',
				style : 'btn-danger btn-sm',
				click : function(page, pageSize, key) {
					var checked = $.suredy.list.checked($('table.bid-agency-list'));

					if (checked.length <= 0) {
						alert('请勾选需要删除的项');
						return false;
					}

					var ids = [];

					checked.each(function(i) {
						var $this = $(this);

						ids[ids.length] = $this.data('id');
					});

					$.ajax({
						url : '${request.contextPath}/config/bid-agency/delete',
						data : {
							ids : ids
						},
						type : 'post',
						dataType : 'json',
						success : function(data) {
							if (!data || !data.success) {
								alert(data.msg || '删除失败！');
								return false;
							}

							$.suredy.loadContent('${request.contextPath}/config/bid-agency/list');
						},
						error : function() {
							alert('删除失败！');
						}
					});
				}
			} ]
		});
	});
</script>